package com.gs.SynPatrolRep.presenter;


import com.google.gson.reflect.TypeToken;
import com.gs.SynPatrolRep.apiresult.ApiResultData;
import com.gs.SynPatrolRep.apiresult.PagedList;
import com.gs.SynPatrolRep.db.dto.CancelPalBillDto;
import com.gs.SynPatrolRep.db.dto.PalBillApprovalDto;
import com.gs.SynPatrolRep.db.dto.PalBillDto;
import com.gs.SynPatrolRep.db.dto.PalBillListDto;
import com.gs.SynPatrolRep.db.query.BaseQuery;
import com.gs.SynPatrolRep.model.PalBillModel;
import com.gs.SynPatrolRep.model.listener.OnResultListener;
import com.gs.SynPatrolRep.view.IPalBillListView;
import com.gs.SynPatrolRep.view.IPalBillSiteView;

public class PalBillSitePresenter extends BasePresenter<IPalBillSiteView> {
    private PalBillModel palBillModel = new PalBillModel();

    public void getData(String id) {
        getView().showLoading();
        palBillModel.getPalBills(id, new OnResultListener() {
            @Override
            public void onSuccess(Object apiResult) {
                if (getView() != null) {
                    getView().onGetDataSuccess((ApiResultData<PalBillDto>) apiResult);
                    getView().hideLoading();
                }
            }

            @Override
            public void onFails(Exception e) {
                if (getView() != null) {
                    getView().onGetDataFails(e);
                    getView().hideLoading();
                }
            }
        }, new TypeToken<ApiResultData<PalBillDto>>() {
        }.getType());
    }

    public void approval(PalBillApprovalDto bean) {
        palBillModel.approval(bean, new OnResultListener() {
            @Override
            public void onSuccess(Object apiResult) {
                if (getView() != null) {
                    getView().onApprovalSuccess((ApiResultData<Object>) apiResult);
                }
            }

            @Override
            public void onFails(Exception e) {
                if (getView() != null) {
                    getView().onApprovalFails(e);
                }
            }
        }, new TypeToken<ApiResultData<Object>>() {
        }.getType());
    }
}
